<template>
  <div class="article">
    <!-- 搜索 -->
    <div class="nav">
      <div class="nav_box">
        <router-link to="/home/index" class="router-link-active"
          >首页</router-link
        >
        <el-icon color="#999">
          <DArrowRight />
        </el-icon>
        <router-link to="/home/article" class="router-link-active"
          >党员充电站</router-link
        >
      </div>
    </div>
    <el-container>
      <el-aside>
        <div class="title" style="cursor: pointer" @click="zkclick">
          <el-icon color="#e02020" class="ico_1">
            <Menu />
          </el-icon>
          <div class="tet">党员充电站</div>
          <el-icon color="#e02020" class="ico_2" v-if="zk">
            <ArrowUp />
          </el-icon>
          <el-icon color="#e02020" class="ico_2" v-else>
            <ArrowDown />
          </el-icon>
        </div>
        <div
          v-if="zk"
          :class="myitem == i ? 't_item' : 't_item1'"
          v-for="(item, i) in list"
          :key="i"
          style="cursor: pointer"
          @click="citem(i)"
        >
          <div class="tet">
            {{ item.name }}
          </div>
        </div>
      </el-aside>
      <el-main>
        <div class="art">
          <div class="title">
            <div
              :class="mytit == i ? 't_nav' : 't_nav1'"
              v-for="(item, i) in list1"
              :key="i"
              style="cursor: pointer"
              @click="tit(i)"
            >
              <div class="tet">
                {{ item.name }}
              </div>
            </div>
          </div>
          <!-- 内容 -->
          <div class="a_con" v-if="data.length > 0">
            <div
              class="a_item"
              v-for="item in data"
              :key="item.id"
              style="cursor: pointer"
              @click="articles(item.id)"
            >
              <div class="it_top">
                {{ item.title }}
              </div>
              <div class="it_bom">
                <div class="p_lef">{{ item.create_time }}</div>
                <div class="p_rig">浏览:&nbsp{{ item.views }}</div>
              </div>
            </div>
          </div>
          <div class="con_bom" v-if="total > 0">
            <div class="cc">共{{ total }}条</div>
            <el-pagination
              v-model:page-size="pageSize"
              background
              layout="prev, pager, next"
              :total="total"
              @next-click="nextclick"
              @prev-click="prevclick"
              @change="change1"
            />
          </div>
          <div class="rq" v-else>
            <img src="@/image/容器.svg" alt="" />
            <div>暂无信息</div>
          </div>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { getnetworkApi, getnetworkApi1 } from '@/api/user'
import { useRouter } from 'vue-router'
let Router = useRouter()
function articles(id: any) {
  // Router.push('/home/articles')
  // Router.push({ path: '/home/articles', query: { id } })
  window.open(`/pc/home/articles?id=${id}`, '_blank')
}
let names = ref({
  cid: 1,
  sort: 'views',
  keyword: '',
  page: 1,
  page_size: 10
})
const data = ref([
  {
    create_time: '2024-01-23',
    id: 9,
    title: '最美网文替代文字xxx替代文字xxx替代文字xxx替代文字xxx',
    views: 22
  }
])
const getnetwork = () => {
  getnetworkApi(names.value).then(res => {
    data.value = res.data.data.data
    total.value = res.data.data.total
    console.log(res)
  })
}
getnetwork()
const total = ref(0)
const list = ref([{ id: 1, name: '文章分类1' }])
getnetworkApi1().then(res => {
  // console.log(res, '分类')
  // console.log('list', list.value)
  list.value = res.data.data
})

const myitem = ref(0)
const citem = (ev: number) => {
  names.value.page = 1
  names.value.cid = list.value[ev].id
  getnetwork()
  myitem.value = ev
  // console.log(ev, myitem.value)
}
const list1 = ref([{ name: '浏览量' }, { name: '发布时间' }])
const mytit = ref(0)
const tit = (ev: number) => {
  if (ev == 0) {
    names.value.sort = 'views'
  } else {
    names.value.sort = 'create'
  }
  getnetwork()
  mytit.value = ev
  // console.log(ev, mytit.value)
}
// 分页
const pageSize = ref(10)
const nextclick = () => {
  names.value.page++
  getnetwork()
}
const prevclick = () => {
  names.value.page--
  getnetwork()
}
const change1 = (e: any) => {
  console.log(e)
  names.value.page = e
  getnetwork()
}
// 展开
const zk = ref(true)
const zkclick = () => {
  zk.value = !zk.value
}
</script>

<style lang="scss" scoped>
.rq {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 100px;

  img {
    width: 228px;
    height: 226px;
  }
}

.el-container {
  .el-main {
    position: relative;
    height: 1200px;
    background-color: #fff;
    width: 816px;
    overflow: hidden;

    .art {
      margin-top: -18px;
      margin-left: -16px;
      width: 800px;
      background-color: #fff;

      // padding: 0 16px;
      .con_bom {
        position: absolute;
        bottom: 100px;
        left: 50%;
        display: flex;
        transform: translateX(-50%);

        .cc {
          width: 60px;
          margin-top: 8px;
        }
      }

      .a_con {
        padding: 0 16px;

        .a_item {
          border-bottom: 1px solid #d8d8d8;
          height: 93px;

          .it_top {
            padding-top: 20px;
            font-size: 16px;
            font-weight: 600;
            color: #1a1a1a;
            white-space: nowrap;
            /* 防止文本换行 */
            overflow: hidden;
            /* 隐藏溢出内容 */
            text-overflow: ellipsis;
            /* 当文本溢出时，使用省略号表示 */
            width: 700px;
            /* 定义容器宽度 */
          }

          .it_bom {
            display: flex;
            justify-content: space-between;
            margin-top: 12px;
            font-size: 14px;
            font-weight: normal;
            color: #767676;
          }
        }
      }

      .title {
        display: flex;
        padding-top: 22px;

        .t_nav {
          font-size: 16px;
          font-weight: 600;
          color: #e02020;
        }

        .t_nav1 {
          font-size: 16px;
          font-weight: 600;
          color: #767676;
        }

        .tet {
          width: 400px;
          text-align: center;
          margin-bottom: 11px;
        }
      }
    }
  }

  .el-aside {
    width: 232px;
    background-color: #fff;
    margin: 0 16px;

    .t_item {
      margin: 4px auto;
      width: 216px;
      height: 36px;
      line-height: 36px;
      color: #e02020;
      font-size: 14px;
      border-radius: 2px;
      background: rgba(224, 32, 32, 0.1);

      .tet {
        margin-left: 44px;
      }
    }

    .t_item1 {
      margin: 4px auto;
      width: 216px;
      height: 36px;
      line-height: 36px;
      color: rgba(0, 0, 0, 0.6);
      font-size: 14px;

      .tet {
        margin-left: 44px;
      }
    }

    .title {
      display: flex;
      width: 216px;
      height: 36px;
      line-height: 36px;
      margin: 16px 8px 0;

      .ico_1 {
        margin: 10px 8px 0 20px;
        font-size: 15px;
      }

      .ico_2 {
        font-size: 15px;
        margin: 10px 8px 0 80px;
      }

      .tet {
        font-size: 14px;
        color: #e02020;
      }
    }
  }
}

.nav {
  height: 54px;
  line-height: 54px;
  background-color: #fff;
  margin-bottom: 16px;

  .nav_box {
    display: flex;
    align-items: center;
    margin-left: 44px;
    font-size: 16px;
    color: #999999;

    .router-link-active {
      font-size: 16px;
      color: #999999 !important;
      text-decoration: none;
    }

    .el-icon {
      margin: 0 10px 0 10px;
      line-height: 55px;
    }
  }
}

// @media (max-width: 1025px) {
.article {
  width: 1080px;
  margin: 0 auto;
  background-color: #f0f0f0;
}

// }
</style>
